.text
.global main

# used in 1-2, relocate kernel and load kernel size in bootblock

main:
	# 1) call BIOS print string "It's bootblock!"
	dla		$a0, msg 			               # load msg address as parameter in a0
	ld		$t1, printstr		             # load func printstr address to $t0
	jalr	$t1  			                   # jump to printstr 
	 

	# 2) call BIOS read kernel in SD card
  ld    $a0, kernel
  li    $a1, 0x200                   # offset = 200
  lw    $t2, 0xffffffffa08001fc      # read kernel sector in address 508
  sll   $a2, $t2, 9                  # kernel_sector * 512 = rkernel_size

  ld    $t1, read_sd_card            # load func read_sd_card address to $t1
	jalr  $t1
 
  # 3) jump to kernel
	ld    $t0, kernel_main
  jalr  $t0

# 4) while(1) --> stop here
stop:
	j stop

.data

msg: .ascii "It's a bootloader!!!(relocate and add big kernel!)\n"


# 1. PMON read SD card function address
# read_sd_card();
read_sd_card: .dword 0xffffffff8f0d5e10

# 2. PMON print string function address
# printstr(char *string)
printstr: .dword 0xffffffff8f0d5534

# 3. PMON print char function address
# printch(char ch)
printch: .dword 0xffffffff8f0d5570

# 4. kernel address (move kernel to here ~)
kernel: .dword 0xffffffffa0800200

# 5. kernel main address (jmp here to start kernel main!)
kernel_main: .dword 0xffffffffa0800200
